import './index.scss';
import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
export default {
  name: 'findpublic',
  data () {
    return {
      pageNo: 1,
      pageSize: 10,
      newsList: []
    }
  },
  mounted () {
    if (this.$emit('ifOpenid')) {
      this.$emit('ifOpenid', this.$route.path)
    }
    this.goNewsList();
  },
  methods: {
    goNewsList () {
      http.post(CONSTANT.NEWS_LIST, {
        pageNo: this.pageNo,
        pageSize: this.pageSize
      }, (res) => {
        console.log(res)
        if (res.code == 200) {
          this.newsList = res.list;
        } else if (res.code == 500) {
          if (res.errmsg == '没有更多的文章') {
            if (this.pageNo > 1) {
              this.pageNo--;
            }
            alert('没有更多的文章了');
          }
        }
      });
    },
    nextNews () {
      this.pageNo++;
      this.goNewsList();
    },
    upNews () {
      this.pageNo--;
      if (this.pageNo <= 0) {
        this.pageNo++;
        alert('已经是第一页了')
        return
      } else {
        this.goNewsList();
      }
    },
    goArticleDetails (e) {
      this.$router.push({path: '/articleDetails', query: {'id': e}})
    },
    comeBack () {
      window.history.back();
    }
  }
}
